import { defineStore } from 'pinia'
import en from './en.json'
import zh_CN from './zh_CN.json'

// 准备翻译的语言环境信息
const messages = {
  zh_CN,
  en,
}
type moduleType = 'takeOut' | 'shoppingMall' | 'seaTransportation' // 外卖，商城，海运
export type localesType = 'zh_CN' | 'en' //中文，英文
interface userStoreProps {
  lang: localesType
  module: moduleType
  messages: Record<localesType, any>
}
const defaultLang: localesType = 'zh_CN'
const i18nStore = defineStore('i18n', {
  state: (): userStoreProps => {
    return {
      messages,
      lang: defaultLang,
      module: 'takeOut',
    }
  },
  actions: {
    t(msg) {
      return this.messages[this.lang][msg]
    },
    setLang(lang: localesType) {
      this.lang = lang
    },
    setModule(module: moduleType) {
      this.module = module
    },
  },
})
export default i18nStore
